<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <link rel="stylesheet" href="../static/layui/css/layui.css">
</head>
<body>
<div class="layui-container" style="width: 100%;">
    <div class="layui-row">
        <form class="layui-form" lay-filter="form1">
            <div class="layui-form-item layui-inline">
                <input class="layui-input" placeholder="病人名" name="userName">
            </div>
            <div class="layui-form-item layui-inline">
                <input class="layui-input" placeholder="病人账号" name="userAccount">
            </div>
            <div class="layui-form-item layui-inline">
                <input class="layui-input" placeholder="预约时间" name="orderTime" id="orderTime" autocomplete="off">
            </div>
            <div class="layui-form-item layui-inline">
                <input class="layui-input" placeholder="创建时间" name="createStartTime" id="createStartTime"
                       autocomplete="off">
            </div>
            <div class="layui-form-item layui-inline">
                <input class="layui-input" placeholder="至" name="createEndTime" id="createEndTime" autocomplete="off">
            </div>
            <div class="layui-form-item layui-inline" style="float: right;">
                <button class="layui-btn" type="button" onclick="table1Search()">查询</button>
            </div>
        </form>
    </div>
    <div class="layui-row">
        <div class="">
            <button class="layui-btn layui-bg-green" type="button" style="width: 77px;" onclick="verifyOrder('02')">通过
            </button>
            <button class="layui-btn layui-bg-cyan" type="button" onclick="verifyOrder('03')">不通过</button>
        </div>
    </div>
    <div class="layui-row">
        <table id="table1" class="layui-table"></table>
    </div>
</div>
</body>
<script type="text/javascript" src="../static/layui/layui.all.js"></script>
<script type="text/javascript" src="../static/config.js"></script>
<script type="text/javascript">
    const $ = layui.$;
    const element = layui.element;
    const layer = layui.layer;
    const form = layui.form;
    const table = layui.table;
    const laydate = layui.laydate;

    laydate.render({elem: '#orderTime'});
    laydate.render({
        elem: '#createStartTime',
        type: 'datetime'
    });
    laydate.render({
        elem: '#createEndTime',
        type: 'datetime'
    });

    //执行渲染
    const table1 = table.render({
        elem: '#table1',
        url: baseUrl + "/hospital-doctor/order/getOrderByDoctorId",
        headers: {
            "x-token": localStorage.getItem("x-token")
        },
        height: "700px",
        method: "post",
        even: true,
        page: true,
        cols: [[
            {type: 'checkbox', title: '', width: 88},
            {field: 'status', title: '状态', width: 280},
            {field: 'userAccount', title: '病人身份证号'},
            {field: 'userName', title: '病人名'},
            {field: 'orderTime', title: '预约时间'},
            {field: 'createTime', title: '创建时间'},
        ]]
    });

    function table1Search() {
        const form1 = form.val("form1");
        console.log(form1);
        table1.reload({
            where: form1,
            page: {
                curr: 1
            }
        });
    }

    function verifyOrder(status) {
        const obj = table.checkStatus("table1");
        if (obj == null || obj.data.length <= 0) {
            layer.msg("请选择一条数据");
            return;
        }
        const arr = [];
        for (const datum of obj.data) {
            arr.push(datum.objId);
        }
        $.post({
            url: baseUrl + "/hospital-doctor/order/verifyOrder/" + status,
            data: {
                orderIds: arr
            },
            traditional: true,
            success: function (res) {
                console.log(res);
                table1Search();
            }
        });
    }

</script>
</html>